﻿package fj.ui
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	public class FJRadioGroup extends MovieClip
	{
		private var _arrayChecks:Array;
		private var _selected:String;
		
		public function FJRadioGroup():void
		{
			_arrayChecks = new Array();
			for( var i:uint; i < numChildren; i++ ){
				var btn:MovieClip = getChildAt( i ) as MovieClip;
				_arrayChecks.push( btn );
				btn.addEventListener( MouseEvent.CLICK, btnClick );
			}
			selected = _arrayChecks[0].name;
		}
		public function set selected( s:String ):void
		{
			_selected = s;
			for( var i:uint = 0; i < _arrayChecks.length; i++ ){
				var check:MovieClip = _arrayChecks[i] as MovieClip;
				if(check.selected){
					check.selected = false;
				}
			}
			var checkSelected:MovieClip = getChildByName(s) as MovieClip;
			checkSelected.selected = true;
		}
		public function get selected():String
		{
			return _selected;
		}
		private function btnClick( e:MouseEvent ):void
		{
			selected = e.currentTarget.name;
		}
	}
}